<template>
    <div id="addTo">
        <div class="wThis">
            <img :src="imgUrl">
            <span class="text">{{title}}</span>
        </div>
        <div class="talking">
            <div class="line">
                <textarea placeholder="评价一下商品吧，您的评价还能帮助到其他小伙伴哦～" v-model="assessVal"></textarea>
                <div class="uploadContainer">
                    <div class="uploadImg">
                        <label id="first" @click="uploadsImg($event)"></label>
                    </div>
                    <div class="uploadImg">
                        <label id="second" @click="uploadsImg($event)"></label>
                    </div>
                    <div class="uploadImg">
                        <label id="third" @click="uploadsImg($event)"></label>
                    </div>
                    <div class="uploadImg">
                        <label id="fourth"  @click="uploadsImg($event)"></label>
                    </div>
                </div>
            </div>
        </div>
        <div class="end">
            <button class="btn" @click="goSucc">发表追评</button>
        </div>

    </div>
</template>
<script>
    import config from "../config/config.js";
    import share from "../share/share.js";
    import store from "../store/newStore.js";
    export default{
        data(){
            return{
                hidden:true,
                show:false,
                orderid:'',
                title:'',
                imgUrl:'',
                assessVal:'',
                imgs:[]
            }
        },
        methods:{
            goAllorder(){
                this.$router.push({
                    path:"/allorder",
                    query:{
                        showWrapper:true
                    }
                })
            },

            uploadsImg($event){
                var that=this;
                var id=$event.currentTarget.getAttribute('id');
                wx.chooseImage({
                    count: 1, // 默认9
                    sizeType: ['original', 'compressed'],
                    sourceType: ['album', 'camera'],
                    success: function (res) {
                        var localIds = res.localIds;
                        var UploadsImg=document.createElement('div'),
                            img=document.createElement('img'),
                            closeX=document.createElement('span');
                        closeX.setAttribute('style','background:url(https://khh-server.oss-cn-beijing.aliyuncs.com/resourse/IMG/static/change/close_d.png);position: absolute;top: -.15rem;right: -.15rem;width: .34rem;height: .34rem;background-size:cover;');
                        img.setAttribute('src',localIds[0]);
                        img.setAttribute('style','width: 1.18rem;height: 1.18rem;border-radius: .08rem;');
                        UploadsImg.setAttribute('style','position: absolute;top: -1px;left: -1px;width: 1.18rem;height: 1.18rem;');
                        UploadsImg.appendChild(img);
                        UploadsImg.appendChild(closeX);
                        document.getElementById(id).appendChild(UploadsImg);
                        wx.uploadImage({
                            localId:localIds[0],
                            isShowProgressTips: 1,
                            success: function (res) {
                                var serverId = res.serverId;
                                that.imgs.push(serverId);
                                closeX.onclick=function($event){
                                    $event.stopPropagation();
                                    var __self=this;
                                    __self.parentNode.parentNode.removeChild(__self.parentNode);
                                    that.imgs.pop(serverId);
                                }
                            }
                        });
                    }
                });
            },
            goSucc(){
                var assessObj={
                    orderid:this.$route.query.orderid,
                    value:this.assessVal,
                    imgs:this.imgs
                };
                var value=JSON.stringify({"orderid":assessObj.orderid,"value":assessObj.value,"imgs":assessObj.imgs,"token":localStorage.getItem('token')}),
                    key=demo(value);
                axios.post('/Home/Remark/PushRemarkAdd',{
                    value:value,
                    key:key
                },config)
                    .then(function(response) {
                        if(response.data.code==200){
                           this.goAllorder()
                        }
                    }.bind(this))
                    .catch(function (error) {
                        console.log(error);
                    });
            },
        },
        activated(){
            this.orderid=this.$route.query.orderid;
            this.title=this.$route.query.title;
            this.imgUrl=this.$route.query.imgUrl;
            share({})

        }
    }
</script>

<style>
    
</style>